﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Manage_allquestion : ManagePageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindType();
            BindDiff();
            BindQuestions();

        }
    }

    private void BindType()
    {
        StringBuilder sb = new StringBuilder();
        List<Exam.Core.Model.QuestionType> Typelist = new Exam.Core.DAL.QuestionType().getQuestionTypeList();
        foreach (Exam.Core.Model.QuestionType obj in Typelist)
        {
            QType.Items.Add(new ListItem(obj.QuestionTypeTitle.Trim(), obj.QuestionTypeId.Trim()));
            sb.Append(obj.QuestionTypeId.Trim() + ",");

        }
        QType.Items.Insert(0, new ListItem("所有题型", sb.ToString().Trim(',')));
    }

    private void BindDiff()
    {
        StringBuilder sb = new StringBuilder();
        List<Exam.Core.Model.QuestionDifficulty> Difflist = new Exam.Core.DAL.QuestionDifficulty().getQuestionDifficultyList();
        foreach (Exam.Core.Model.QuestionDifficulty obj in Difflist)
        {
            QDifficulty.Items.Add(new ListItem(obj.QuestionDifficultyTitle.Trim(), obj.QuestionDifficultyId.Trim()));
            sb.Append(obj.QuestionDifficultyId.Trim() + ",");
            

        }
        QDifficulty.Items.Insert(0, new ListItem("所有难度", sb.ToString().Trim(',')));

    }
    private void BindQuestions()
    {
        List<Exam.Core.Model.Question> list = new Exam.Core.DAL.Question().getQuestionAllList();
        rp.DataSource = list;
        rp.DataBind();
    }
    protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Exam.Core.Model.Question rw = (Exam.Core.Model.Question)e.Item.DataItem;
            StringBuilder sb = new StringBuilder();
            List<Exam.Core.Model.QuestionOpts> opts = new Exam.Core.DAL.QuestionOpts().getOptsListByQuestionId(int.Parse(rw.QuestionId.Trim()));
            foreach(Exam.Core.Model.QuestionOpts obj in opts){
                sb.Append("<div>" + obj.QuestionOptsValue+"、" + obj.QuestionOptsText + "<div>");
            }
            Literal litTj = (Literal)e.Item.FindControl("litipts");
            litTj.Text = sb.ToString();
        }

    }

    protected string getQType(string id)
    {
        string title = "";
        foreach (ListItem item in QType.Items)
        {
            if (id.Trim() == item.Value.Trim())
            {
                title = item.Text.Trim();
                break;
            }
        }
        return title.Trim();
    }
    protected string getQDiff(string id)
    {
        string title = "";
        foreach (ListItem item in QDifficulty.Items)
        {
            if (id.Trim() == item.Value.Trim())
            {
                title = item.Text.Trim();
                break;
            }
        }
        return title.Trim();
    }

    private int GetPageIndex()
    {
        int index = 0;
        if (int.TryParse(Request.QueryString["page"], out index))
            index--;
        return index;
    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //BindCourse();
        //BindType();
        //BindDiff();
        BindQuestions();
    }

    protected string getAnswer(string str)
    {
        if (str == "TRUE")
            return "对";
        if (str == "FALSE")
            return "错";
        return str;
    }

}